package com.zhukaiyuan.oauth2.sys.controller;

import com.zhukaiyuan.oauth2.sys.service.LoginService;
import com.zhukaiyuan.oauth2.utils.Header;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 注销
 *
 * @author Lusifer
 * @since v1.0.0
 */
@RestController
@RequestMapping(value = "sys/logout")
public class LogoutController {

    @Resource
    public HttpServletRequest request;


    @Autowired
    private LoginService loginService;
    /**
     * 注销用户
     *
     * @return
     */
    @PostMapping
    public String users() {
        return logout();
    }

    // 私有方法 ------------------------------------------- Begin

    private String logout() {
        String token = Header.getAuthorization(request.getHeader("Authorization"));
        String logout = loginService.logout(token);
        return logout;
    }
}